package com.qnzw.zjmy.home;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.android.volley.Request;
import com.android.volley.VolleyError;
import com.anythink.banner.api.ATBannerExListener;
import com.anythink.banner.api.ATBannerView;
import com.anythink.core.api.ATAdInfo;
import com.anythink.core.api.ATAdRevenueListener;
import com.anythink.core.api.ATAdStatusInfo;
import com.anythink.core.api.ATNetworkConfirmInfo;
import com.anythink.core.api.AdError;
import com.anythink.interstitial.api.ATInterstitial;
import com.anythink.interstitial.api.ATInterstitialListener;
import com.anythink.nativead.api.ATNativeAdView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.gson.Gson;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.qnzw.zjmy.activity.CallBack;
import com.qnzw.zjmy.ad.kaku.TaKuInterstitialFullAd;
import com.qnzw.zjmy.home.ui.enums.TaKuAdPositionEnum;
import com.qnzw.zjmy.home.ui.model.TrandsName;
import com.qnzw.zjmy.home.ui.model.vo.AdRecordSecondaryVo;
import com.qnzw.zjmy.home.ui.model.vo.AdRecordVo;
import com.qnzw.zjmy.refresh.init.GameApplication;
import com.qnzw.zjmy.utils.RSAEncrypt;
import com.qnzw.zjmy.volley.httpUtil.interfase.HUCCallBackInterfase;
import com.qnzw.zjmy.wxapi.WXEntryActivity;
import com.umeng.commonsdk.UMConfigure;
import com.qnzw.zjmy.R;
import com.qnzw.zjmy.ad.MediationBannerAd;
import com.qnzw.zjmy.ad.MediationTablePlaqueAd;
import com.qnzw.zjmy.ad.kaku.TaKuRewardAdCallback;
import com.qnzw.zjmy.ad.kaku.banner.TaKuBannerAdFour;
import com.qnzw.zjmy.adapter.ViewPageAdapter;
import com.qnzw.zjmy.config.UrlAddressConfig;
import com.qnzw.zjmy.config.UrlConfig;
import com.qnzw.zjmy.home.fragment.Category2Fragment;
import com.qnzw.zjmy.home.fragment.ContentFragment;
import com.qnzw.zjmy.home.fragment.HomeFragment;
import com.qnzw.zjmy.home.fragment.MyFragmentStyle2;
import com.qnzw.zjmy.home.ui.enums.RedisEnum;
import com.qnzw.zjmy.home.ui.model.User;
import com.qnzw.zjmy.home.ui.model.VersionUpdate;
import com.qnzw.zjmy.home.ui.model.vo.BaseVo;
import com.qnzw.zjmy.home.ui.model.vo.UserDailyActivityVo;
import com.qnzw.zjmy.service.RiskService;
import com.qnzw.zjmy.utils.StringSplit;
import com.qnzw.zjmy.utils.UpdateManager;
import com.qnzw.zjmy.utils.VersionUtils;
import com.qnzw.zjmy.utils.risk.DeviceUtils;
import com.qnzw.zjmy.utils.risk.RiskUtils;
import com.qnzw.zjmy.utils.risk.VirtualApkCheckUtil;
import com.qnzw.zjmy.view.NavigationTabBar;
import com.qnzw.zjmy.volley.BaseActivity;
import com.qnzw.zjmy.volley.state.HUCState;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;

/**
 * Created by GIGAMOLE on 28.03.2016.
 */
public class HorizontalNtbActivity extends BaseActivity {
    private SharedPreferences sp;
    private NavigationTabBar navigationTabBar;
    private VirtualApkCheckUtil virtualApkCheckUtil;
    private RiskUtils riskUtils;
    private DeviceUtils deviceUtils;

    private MediationBannerAd mediationBannerAd;
    private MediationTablePlaqueAd mediationTablePlaqueAd;
    private TaKuInterstitialFullAd taKuInterstitialFullAd;

    //加载
    private AlertDialog alertDialog;
    private AlertDialog permissionDialog;
    //更新
    private UpdateManager updateManager;

    private TaKuRewardAdCallback taKuRewardAdCallback;

    private final Handler handler = new Handler();
    private Runnable runnable;


    private ATBannerView mBannerView;
    private WebView mWebView;

    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        mWebView.saveState(outState);
    }

    @Override
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        mWebView.restoreState(savedInstanceState);
    }

    @RequiresApi(api = Build.VERSION_CODES.S)
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_horizontal_ntb);
        mWebView = findViewById(R.id.web);
        FrameLayout fl_Top_Banner = findViewById(R.id.fl_Top_Banner);
        ATNativeAdView ATNativeAdView = findViewById(R.id.tk_Information_Flow);
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 在 WebView 内加载 URL
                view.loadUrl(url);
                return true; // 返回 true 表示拦截此 URL
            }
        });
        mWebView.setWebContentsDebuggingEnabled(true);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webSettings.setDomStorageEnabled(true);

        virtualApkCheckUtil = VirtualApkCheckUtil.getSingleInstance();
        deviceUtils = DeviceUtils.getInstance();

        riskUtils = RiskUtils.getInstance();
//        initAd();
        //initUI();
//        initUi2();
        load();

        //检测更新
        updateManager = new UpdateManager(this);

        if (XXPermissions.isGranted(HorizontalNtbActivity.this, Permission.MANAGE_EXTERNAL_STORAGE, Permission.REQUEST_INSTALL_PACKAGES, Permission.READ_PHONE_STATE)) {
            loadVersion();
        } else {


            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            View root = LayoutInflater.from(this).inflate(R.layout.permission_dialog, null);
            dialog.setView(root);
            root.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    XXPermissions.with(HorizontalNtbActivity.this)
                            .permission(Permission.MANAGE_EXTERNAL_STORAGE)
                            .permission(Permission.REQUEST_INSTALL_PACKAGES)
                            .permission(Permission.READ_PHONE_STATE)
                            .request(new OnPermissionCallback() {

                                @Override
                                public void onGranted(@NonNull List<String> permissions, boolean allGranted) {
                                    if (!allGranted) {
                                        Toast.makeText(HorizontalNtbActivity.this, "获取部分权限成功，但部分权限未正常授予", Toast.LENGTH_SHORT).show();
                                        return;
                                    }
                                    permissionDialog.dismiss();
                                    permissionDialog = null;

                                    loadVersion();
                                }

                                @Override
                                public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
                                    if (doNotAskAgain) {
                                        Toast.makeText(HorizontalNtbActivity.this, "被永久拒绝授权，请手动授予权限", Toast.LENGTH_SHORT).show();

                                        // 如果是被永久拒绝就跳转到应用权限系统设置页面
                                        XXPermissions.startPermissionActivity(HorizontalNtbActivity.this, permissions);
                                    }
                                }
                            });

                }
            });
            permissionDialog = dialog.create();
            permissionDialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
            permissionDialog.setCancelable(false);
            permissionDialog.show();

        }


        //用户id
        String id = getSharedPreferences("id");
        String insert_full_screen = getSharedPreferences("insert_full_screen");

        //全屏广告id
        String fullAdId = getSharedPreferences(RedisEnum.AD_INSERT_FULL_SCREEN.getKey());
        //激励广告id
        String RewardAd = getSharedPreferences(RedisEnum.INCENTIVE_VIDEO_CALLBACK.getKey());
        //信息流广告id
        String InformationFlowId = StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 0);
        //半屏广告id
        String HalfId = getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey());
        //答题时间
        String time_interval_answer = getSharedPreferences(RedisEnum.TIME_INTERVAL_ANSWER.getKey());
        //广告总次数
        String daily_task_frequency = getSharedPreferences(RedisEnum.DAILY_TASK_FREQUENCY.getKey());
        //oaid
        String oaId = getSharedPreferences(RedisEnum.OAID.getKey());
        //用户邀请码
        String code = getSharedPreferences("code");
        //是否提现
        String risk_withdrawal_open_app = getSharedPreferences(RedisEnum.RISK_WITHDRAWAL_OPEN_APP.getKey());
        //是否开启广告
        String ta_ku = getSharedPreferences("isOpen");

        mWebView.addJavascriptInterface(new CallBack(this, ATNativeAdView, id,
                HalfId,
                insert_full_screen,
                fullAdId,
                RewardAd,
                InformationFlowId,
                time_interval_answer,
                daily_task_frequency,
                oaId,
                code,
                risk_withdrawal_open_app,
                ta_ku
        ), "AndroidJSBridge");
        mWebView.loadUrl("https://cocos.hlghyx.com/zjmy/");
//        mWebView.loadUrl("https://cocos.hlghyx.com/xkcshj/");
        mBannerView = new ATBannerView(this);
        mBannerView.setPlacementId(getSharedPreferences(RedisEnum.BANNER.getKey()));
        int width = getResources().getDisplayMetrics().widthPixels;//定一个宽度值，比如屏幕宽度
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        mBannerView.setLayoutParams(new FrameLayout.LayoutParams(width, height));
        mBannerView.setBannerAdListener(new ATBannerExListener() {
            @Override
            public void onDeeplinkCallback(boolean b, ATAdInfo atAdInfo, boolean b1) {

            }

            @Override
            public void onDownloadConfirm(Context context, ATAdInfo atAdInfo, ATNetworkConfirmInfo atNetworkConfirmInfo) {

            }

            @Override
            public void onBannerLoaded() {
                ATAdStatusInfo atAdStatusInfo = mBannerView.checkAdStatus();
                if (!atAdStatusInfo.isReady()) {
                    return;
                }
                if (ObjectUtil.isNotNull(fl_Top_Banner)) {
                    fl_Top_Banner.removeAllViews();
                }
                fl_Top_Banner.addView(mBannerView);
            }

            @Override
            public void onBannerFailed(AdError adError) {
                Log.e("yqq", adError.getDesc());
            }

            @Override
            public void onBannerClicked(ATAdInfo atAdInfo) {

            }

            @Override
            public void onBannerShow(ATAdInfo atAdInfo) {
                Log.e("yqq", "banner展示");
            }

            @Override
            public void onBannerClose(ATAdInfo atAdInfo) {
                if (mBannerView != null && mBannerView.getParent() != null) {
                    ((ViewGroup) mBannerView.getParent()).removeView(mBannerView);
                }
            }

            @Override
            public void onBannerAutoRefreshed(ATAdInfo atAdInfo) {

            }

            @Override
            public void onBannerAutoRefreshFail(AdError adError) {

            }
        });
        mBannerView.setAdRevenueListener(new ATAdRevenueListener() {
            @Override
            public void onAdRevenuePaid(ATAdInfo atAdInfo) {
                Double ecpm = atAdInfo.getPublisherRevenue(); //展示广告的价格 0.105234661721
                ecpm = ecpm * 10000;
                int firmId = atAdInfo.getNetworkFirmId();  //展示广告的adn名称
                String sdkName = "other";
                switch (firmId) {
                    case 28://快手
                        sdkName = "ks";
                        break;
                    case 8://腾讯广告(优量汇)
                        sdkName = "gdt";
                        break;
                    case 15://穿山甲（CSJ）
                        sdkName = "pangle";
                        break;
                    default: //其他
                        break;
                }
                AdRecordSecondaryVo adRecordSecondaryVo = new AdRecordSecondaryVo();
                adRecordSecondaryVo.setArsChannel(sdkName);
                adRecordSecondaryVo.setArsRealityMoney(ecpm + "");
                adRecordSecondaryVo.setArsMediationRit(atAdInfo.getNetworkPlacementId());
                adRecordSecondaryVo.setArsPosition("0");
                adRecordSecondaryVo.setArsPrimeRit(atAdInfo.getPlacementId());
                adRecordSecondaryVo.setArsPositionCode(TaKuAdPositionEnum.AD_BANNER_POSITION.getKey());
                adRecordSecondaryVo.setArsShowId(atAdInfo.getShowId());
                MD5 md5 = MD5.create();
                String name = adRecordSecondaryVo.toString() + RSAEncrypt.publicKey;
                String bytes = md5.digestHex(name);
                adRecordSecondaryVo.setSign(bytes);
                hucRequestInterfase.executeStr(HorizontalNtbActivity.this, null, HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.URL_SECONDARY_ADD, hucParameInterfase.getRequestParameter(adRecordSecondaryVo), true);
            }
        });
        mBannerView.loadAd();
     /*   String key = getSharedPreferences(RedisEnum.TA_KU.getKey());
        if (RedisEnum.TA_KU.getValue().equals(key)) {
            //初始化插屏
            TaKuInterstitialAdHome taKuInterstitialAdHome = TaKuInterstitialAdHome.getInstance();

            taKuInterstitialAdHome.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 0));
            TaKuInterstitialAdThree taKuInterstitialAdThree = TaKuInterstitialAdThree.getInstance();
            taKuInterstitialAdThree.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 1));
            TaKuInterstitialAdOneDT taKuInterstitialAdOneDT = TaKuInterstitialAdOneDT.getInstance();
            taKuInterstitialAdOneDT.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 2));
            TaKuInterstitialAdOneCW taKuInterstitialAdOneCW = TaKuInterstitialAdOneCW.getInstance();
            taKuInterstitialAdOneCW.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 3));
            TaKuInterstitialAdOneJL taKuInterstitialAdOneJL = TaKuInterstitialAdOneJL.getInstance();
            taKuInterstitialAdOneJL.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 4));
            TaKuInterstitialAdTwo taKuInterstitialAdTwo = TaKuInterstitialAdTwo.getInstance();
            taKuInterstitialAdTwo.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 5));
            TaKuInterstitialAdSignIn taKuInterstitialAdSignIn = TaKuInterstitialAdSignIn.getInstance();
            taKuInterstitialAdSignIn.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 6));
            TaKuInterstitialAdProCenter taKuInterstitialAdProCenter = TaKuInterstitialAdProCenter.getInstance();
            taKuInterstitialAdProCenter.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 7));
            TaKuInterstitialAdWithdrawal taKuInterstitialAdWithdrawal = TaKuInterstitialAdWithdrawal.getInstance();
            taKuInterstitialAdWithdrawal.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 8));
            TaKuInterstitialAdWithdrawalRecord taKuInterstitialAdWithdrawalRecord = TaKuInterstitialAdWithdrawalRecord.getInstance();
            taKuInterstitialAdWithdrawalRecord.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 9));
            TaKuInterstitialAdRewardRecord taKuInterstitialAdRewardRecord = TaKuInterstitialAdRewardRecord.getInstance();
            taKuInterstitialAdRewardRecord.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 10));
            TaKuInterstitialAdOne taKuInterstitialAdOne = TaKuInterstitialAdOne.getInstance();
            taKuInterstitialAdOne.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 11));
            TaKuInterstitialAdGoodDetail taKuInterstitialAdGoodDetail = TaKuInterstitialAdGoodDetail.getInstance();
            taKuInterstitialAdGoodDetail.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()), StrUtil.COMMA, 12));
            //初始化信息流
            TaKuNativeAdOneDT taKuNativeAdOneDT = TaKuNativeAdOneDT.getInstance();

            taKuNativeAdOneDT.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 0));
            TaKuNativeAdOneJL taKuNativeAdOneJL = TaKuNativeAdOneJL.getInstance();
            taKuNativeAdOneJL.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 1));
            TaKuNativeAdOneCW taKuNativeAdOneCW = TaKuNativeAdOneCW.getInstance();
            taKuNativeAdOneCW.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 2));
            TaKuNativeAdTwo taKuNativeAdTwo = TaKuNativeAdTwo.getInstance();
            taKuNativeAdTwo.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 3));
            TaKuNativeAdSignIn taKuNativeAdSignIn = TaKuNativeAdSignIn.getInstance();
            taKuNativeAdSignIn.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 4));
            TaKuNativeAdProCenter taKuNativeAdProCenter = TaKuNativeAdProCenter.getInstance();
            taKuNativeAdProCenter.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 5));
            TaKuNativeAdGoodDetail taKuNativeAdGoodDetail = TaKuNativeAdGoodDetail.getInstance();
            taKuNativeAdGoodDetail.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 6));
            TaKuNativeAdHome taKuNativeAdHome = TaKuNativeAdHome.getInstance();
            taKuNativeAdHome.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 7));
            TaKuNativeAdCate taKuNativeAdCate = TaKuNativeAdCate.getInstance();
            taKuNativeAdCate.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 8));
            TaKuNativeAdHome2 taKuNativeAdHome2 = TaKuNativeAdHome2.getInstance();
            taKuNativeAdHome2.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.AD_INFORMATION_FLOW.getKey()), StrUtil.COMMA, 9));

            //初始化激励视频
            TaKuRewardAdOne taKuRewardAdOne = TaKuRewardAdOne.getInstance();

            taKuRewardAdOne.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()), StrUtil.COMMA, 0));
            TaKuRewardAdSignIn taKuRewardAdSignIn = TaKuRewardAdSignIn.getInstance();
            taKuRewardAdSignIn.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()), StrUtil.COMMA, 1));
            TaKuRewardAdWithdrawal taKuRewardAdWithdrawal = TaKuRewardAdWithdrawal.getInstance();
            taKuRewardAdWithdrawal.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()), StrUtil.COMMA, 2));
            TaKuRewardAd taKuRewardAd = TaKuRewardAd.getInstance();
            taKuRewardAd.loadAd(this, StringSplit.splitOrNull(getSharedPreferences(RedisEnum.INCENTIVE_VIDEO.getKey()), StrUtil.COMMA, 3));

            TaKuRewardAdCallback taKuRewardAdCallback = TaKuRewardAdCallback.getInstance();
            taKuRewardAdCallback.setUserId(getSharedPreferences("id"));
            taKuRewardAdCallback.setToken(getSharedPreferencesToken("token"));
            taKuRewardAdCallback.loadAd(this, getSharedPreferences(RedisEnum.INCENTIVE_VIDEO_CALLBACK.getKey()));

            //初始化 全屏广告
            if (!getSharedPreferences("insert_full_screen").equals("0") && !getSharedPreferences("insert_full_screen").equals("null")) {
                startRepeatingTask();
            }
        } else {
            //初始化 插屏广告
            mediationTablePlaqueAd = MediationTablePlaqueAd.getInstance();
            mediationTablePlaqueAd.init(getSharedPreferences(RedisEnum.AD_INSERT_HALF_SCREEN.getKey()));
            mediationTablePlaqueAd.loadCacheInterstitialFullAd(this);

            //初始化 Banner
            mediationBannerAd = MediationBannerAd.getInstance();
            mediationBannerAd.init(this, getSharedPreferences(RedisEnum.BANNER.getKey()), 200);
            mediationBannerAd.loadCacheBannerAd();
        }*/
    }

    public void closeRewardPopPanel() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                mWebView.loadUrl("javascript:closeRewardPopPanel()");
                mWebView.evaluateJavascript("javascript:javascript:window.AndroidJSBridgeC.inst.closeRewardPopPanel()", new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String value) {
                        // 处理 H5 返回的值
                    }
                });
            }
        });
    }

    public void setRewardConfig(String data) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                mWebView.loadUrl("javascript:setRewardConfig('" + data + "')");
                mWebView.evaluateJavascript("javascript:window.AndroidJSBridgeC.inst.setRewardConfig('" + data + "')", new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String value) {
                        // 处理 H5 返回的值
                    }
                });
            }
        });
    }

    public void setAdTimeInfo(String AdTimeInfo) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                mWebView.loadUrl("javascript:setAdTimeInfo('" + AdTimeInfo + "')");
                mWebView.evaluateJavascript("javascript:window.AndroidJSBridgeC.inst.setAdTimeInfo('" + AdTimeInfo + "')", new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String value) {
                        // 处理 H5 返回的值
                    }
                });
            }
        });
    }

    public void setRewardCoin(String jinbi) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                mWebView.loadUrl("javascript:setRewardCoin('" + ecpm + "')");
                mWebView.evaluateJavascript("javascript:window.AndroidJSBridgeC.inst.setRewardCoin('" + jinbi + "')", new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String value) {
                        // 处理 H5 返回的值
                    }
                });
            }
        });
    }

    public void setUserInfo(String data) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                mWebView.loadUrl("javascript:setUserInfo('" + data + "')");
                mWebView.evaluateJavascript("javascript:window.AndroidJSBridgeC.inst.setUserInfo('" + data + "')", new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String value) {
                        // 处理 H5 返回的值
                    }
                });
            }
        });
    }

    public void startRepeatingTask() {
        runnable = new Runnable() {
            @Override
            public void run() {
                // 在这里执行定时任务
                String fullAdId = getSharedPreferences(RedisEnum.AD_INSERT_FULL_SCREEN.getKey());
//                taKuInterstitialFullAd = TaKuInterstitialFullAd.getInstance();
//                taKuInterstitialFullAd.loadAd(this, fullAdId);
//                taKuInterstitialFullAd.showAd(this, new AlertDialog.Builder(this).create());

                ATInterstitial mInterstitialAd = new ATInterstitial(HorizontalNtbActivity.this, fullAdId);
                mInterstitialAd.setAdRevenueListener(new ATAdRevenueListener() {
                    @Override
                    public void onAdRevenuePaid(ATAdInfo atAdInfo) {
                        Double ecpm = atAdInfo.getPublisherRevenue(); //展示广告的价格 0.105234661721
                        ecpm = ecpm * 10000;
                        int firmId = atAdInfo.getNetworkFirmId();  //展示广告的adn名称
                        String sdkName = "other";
                        switch (firmId) {
                            case 28://快手
                                sdkName = "ks";
                                break;
                            case 8://腾讯广告(优量汇)
                                sdkName = "gdt";
                                break;
                            case 15://穿山甲（CSJ）
                                sdkName = "pangle";
                                break;
                            default: //其他
                                break;
                        }
                        AdRecordSecondaryVo adRecordSecondaryVo = new AdRecordSecondaryVo();
                        adRecordSecondaryVo.setArsChannel(sdkName);
                        adRecordSecondaryVo.setArsRealityMoney(ecpm + "");
                        adRecordSecondaryVo.setArsMediationRit(atAdInfo.getNetworkPlacementId());
                        adRecordSecondaryVo.setToken(getSharedPreferencesToken("token"));
                        adRecordSecondaryVo.setArsPosition("0");
                        adRecordSecondaryVo.setArsPrimeRit(atAdInfo.getPlacementId());
                        adRecordSecondaryVo.setArsPositionCode(TaKuAdPositionEnum.AD_INTERSTITIAL_FULL_POSITION.getKey());
                        adRecordSecondaryVo.setArsShowId(atAdInfo.getShowId());
                        MD5 md5 = MD5.create();
                        String name = adRecordSecondaryVo.toString() + RSAEncrypt.publicKey;
                        String bytes = md5.digestHex(name);
                        adRecordSecondaryVo.setSign(bytes);
                        hucRequestInterfase.executeStr(HorizontalNtbActivity.this, null, HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.URL_SECONDARY_ADD, hucParameInterfase.getRequestParameter(adRecordSecondaryVo), true);
                    }
                });
                mInterstitialAd.setAdListener(new ATInterstitialListener() {
                    @Override
                    public void onInterstitialAdLoaded() {

                    }

                    @Override
                    public void onInterstitialAdLoadFail(AdError adError) {

                    }

                    @Override
                    public void onInterstitialAdClicked(ATAdInfo atAdInfo) {

                    }

                    @Override
                    public void onInterstitialAdShow(ATAdInfo atAdInfo) {

                    }

                    @Override
                    public void onInterstitialAdClose(ATAdInfo atAdInfo) {

                    }

                    @Override
                    public void onInterstitialAdVideoStart(ATAdInfo atAdInfo) {

                    }

                    @Override
                    public void onInterstitialAdVideoEnd(ATAdInfo atAdInfo) {

                    }

                    @Override
                    public void onInterstitialAdVideoError(AdError adError) {

                    }
                });
                mInterstitialAd.load();
                mInterstitialAd.show(HorizontalNtbActivity.this);

                // 再次调用，延迟5秒
                handler.postDelayed(this, Integer.parseInt(getSharedPreferences("insert_full_screen")) * 1000L);
            }
        };

        // 初始延迟1秒
        handler.postDelayed(runnable, 1000);
    }

    public void stopRepeatingTask() {
        if (runnable != null) {
            handler.removeCallbacks(runnable);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.runFinalization();
        Runtime.getRuntime().gc();
        System.gc();
    }

    private void initUI() {
        final ViewPager viewPager = findViewById(R.id.vp_horizontal_ntb);
        final String[] colors = getResources().getStringArray(R.array.default_preview);
        navigationTabBar = findViewById(R.id.ntb_horizontal);
        final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
        List<Fragment> fragments = new ArrayList<>();
        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.drawable.sel_ic_home), getResources().getColor(R.color.sel_menu_color), "首页"));
//        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.mipmap.icon_cate), Color.parseColor(colors[2]), "分类"));
        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.drawable.sel_ic_answer), getResources().getColor(R.color.sel_menu_color), "答题"));
        models.add(new NavigationTabBar.Model(getResources().getDrawable(R.drawable.sel_ic_my), getResources().getColor(R.color.sel_menu_color), "我的"));
        navigationTabBar.setModels(models);
        fragments.add(new HomeFragment());
//        fragments.add(new CategoryFragment());
        fragments.add(new ContentFragment());
//        fragments.add(new MyFragment());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && fragments.size() > 2) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.home));
        }
        final ViewPageAdapter viewPageAdapter = new ViewPageAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(viewPageAdapter);
        navigationTabBar.setViewPager(viewPager, 0);
        navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(final int position) {
                navigationTabBar.getModels().get(position).hideBadge();
                //  fragments.get(position).setUserVisibleHint(true);
            }

            @Override
            public void onPageScrollStateChanged(final int state) {

            }
        });
/*
        navigationTabBar.post(new Runnable() {
            @Override
            public void run() {
                final View bgNavigationTabBar = findViewById(R.id.bg_ntb_horizontal);
                bgNavigationTabBar.getLayoutParams().height = (int) navigationTabBar.getBarHeight();
                bgNavigationTabBar.requestLayout();
            }
        });*/

    }

    private void initUi2() {
        String BOOTTOM1 = getSharedPreferences(RedisEnum.BOOTTOM1.getKey());
        String BOOTTOM2 = getSharedPreferences(RedisEnum.BOOTTOM2.getKey());

        final ViewPager viewPager = findViewById(R.id.vp_horizontal_ntb);
        viewPager.setOffscreenPageLimit(10);

        List<Fragment> fragments = new ArrayList<>();
        Map<Integer, Integer> menuIndexMap = new HashMap<>(); // 记录菜单项对应的索引

        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_menu);
        Menu menu = bottomNavigationView.getMenu();

        int index = 0;
        int defaultSelectedIndex = -1; // 记录默认选中的索引

        // 处理 menu_1
        if (BOOTTOM1.equals("2")) {
            menu.findItem(R.id.menu_1).setVisible(false);
        } else {
            fragments.add(new HomeFragment());
            menuIndexMap.put(index, R.id.menu_1);
            defaultSelectedIndex = index; // 如果 BOOTTOM1 是 "1"，默认选中 menu_1
            index++;

        }

        // 处理 menu_2
        if (BOOTTOM2.equals("2")) {
            menu.findItem(R.id.menu_2).setVisible(false);
        } else {
            fragments.add(new Category2Fragment());
            menuIndexMap.put(index, R.id.menu_2);
            if (defaultSelectedIndex == -1) { // 只有当 BOOTTOM1 ≠ "1" 时，才选中 menu_2
                defaultSelectedIndex = index;
            }
            index++;

        }

        // 处理 menu_3
        fragments.add(new ContentFragment());
        menuIndexMap.put(index, R.id.menu_3);
        if (defaultSelectedIndex == -1) { // 只有当 BOOTTOM1 ≠ "1" 且 BOOTTOM2 ≠ "1" 时，才选中 menu_3
            defaultSelectedIndex = index;
        }
        index++;

        // 处理 menu_4
        fragments.add(new MyFragmentStyle2());
        menuIndexMap.put(index, R.id.menu_4);
        index++;

        ImmersionBar.with(this).statusBarDarkFont(true).init();
        final ViewPageAdapter viewPageAdapter = new ViewPageAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(viewPageAdapter);
        bottomNavigationView.setItemIconTintList(null);

        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                for (Map.Entry<Integer, Integer> entry : menuIndexMap.entrySet()) {
                    if (entry.getValue() == item.getItemId()) {
                        viewPager.setCurrentItem(entry.getKey(), false); // 设置 ViewPager 页面
                        return true;
                    }
                }
                return false;
            }
        });

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                if (menuIndexMap.containsKey(position)) {
                    int menuItemId = menuIndexMap.get(position);
                    bottomNavigationView.getMenu().findItem(menuItemId).setChecked(true);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

        // **设置默认选中的页面**
        viewPager.setCurrentItem(defaultSelectedIndex, false);
        bottomNavigationView.getMenu().findItem(menuIndexMap.get(defaultSelectedIndex)).setChecked(true);
    }

    //获取用户设备信息ACTIVATION_NOTIFICATION_OPENED

    private void load() {
        loading();
        UserDailyActivityVo baseVo = new UserDailyActivityVo();
        //双开2.0版本
        Intent serviceIntent = new Intent(this, RiskService.class);
        serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startService(serviceIntent);
        //是否分身
        boolean flag = virtualApkCheckUtil.checkByCreateLocalServerSocket(deviceUtils.getPackageName(this));
        baseVo.setUdaSeparation(String.valueOf(flag ? 1 : 2));
        //是否模拟器
        flag = riskUtils.detectEmulator(this);
        baseVo.setUdaSimulator(String.valueOf(flag ? 1 : 2));
        //是否开启调试模式
        flag = deviceUtils.isDeveloperModeEnabled(this);
        baseVo.setUdaDebugMode(String.valueOf(flag ? 1 : 2));
        //是否USB调试模式
        flag = deviceUtils.isAdbEnabled(this);
        baseVo.setUdaUsbMode(String.valueOf(flag ? 1 : 2));
        //是否root
        flag = deviceUtils.isDeviceRooted(this);
        baseVo.setUdaRoot(String.valueOf(flag ? 1 : 2));
        //是否开启无障碍模式
        flag = deviceUtils.isAccessibilityServiceEnabled(this);
        baseVo.setUdaAccessibility(String.valueOf(flag ? 1 : 2));
        //是否开启VPN代理模式
        flag = deviceUtils.isWifiProxy();
        baseVo.setUdaVpnProxy(String.valueOf(flag ? 1 : 2));

        if (UrlAddressConfig.CHANNEL_TYPE != 1) {
            baseVo.setUdaSeparation(String.valueOf(2));
            //是否模拟器
            baseVo.setUdaSimulator(String.valueOf(2));
            //是否开启调试模式
            baseVo.setUdaDebugMode(String.valueOf(2));
            //是否USB调试模式
            baseVo.setUdaUsbMode(String.valueOf(2));
            //是否root
            baseVo.setUdaRoot(String.valueOf(2));
            //是否开启无障碍模式
            baseVo.setUdaAccessibility(String.valueOf(2));
            //是否开启VPN代理模式
            baseVo.setUdaVpnProxy(String.valueOf(2));
        }

        //运营环境当前电池
        baseVo.setUdaBattery(String.valueOf(riskUtils.checkBatteryManager(this)));
        //包名
        baseVo.setUdaPackage(deviceUtils.getPackageName(this));

        //APP名称
        baseVo.setUdaAppName(deviceUtils.getAppName(this));
        //版本号
        baseVo.setUdaVersionCode(VersionUtils.getAppVersionName(this));
        //SIM状态
        baseVo.setUdaSimStatus(String.valueOf(deviceUtils.getSim(this)));
        //SIM运营商
        baseVo.setUdaSimOperator(deviceUtils.getNetworkOperatorName(this));
        //悬浮窗状态
        baseVo.setSystemAlertWindow(deviceUtils.getSystemAlertWindow(this));
        //蓝牙状态
        baseVo.setOpenBluetooth(deviceUtils.getOpenBluetooth(this));
        //当前网络
        baseVo.setUdaNetWork(deviceUtils.getNetworkTypeName(this));
        //Android版本号
        baseVo.setUdaAndroid(deviceUtils.getSystemAndroidVersionCode());
        //Mac地址
        baseVo.setUdaMac(deviceUtils.getMacAddr(this));
        //手机品牌
        baseVo.setUdaBrand(deviceUtils.getSystemAndroidMobilePhoneBrand());
        //手机型号&软件版本
        baseVo.setUdaSystemVersionCode(deviceUtils.getSystemAndroidSystemVersionCode());
        //手机应用总数
        List<PackageInfo> packageInfoList = DeviceUtils.getInstance().getAllApps(this);
        baseVo.setUdaAllApp(String.valueOf(ObjectUtil.isNotEmpty(packageInfoList) ? packageInfoList.size() : 0));
        List<UserDailyActivityVo> userDailyActivityVoList = new ArrayList<>();
        for (PackageInfo packageInfo : packageInfoList) {
            UserDailyActivityVo userDailyActivityVo = new UserDailyActivityVo();
            String name = deviceUtils.getAppName(this, packageInfo.packageName);
            userDailyActivityVo.setUdaPackage(packageInfo.packageName);
            userDailyActivityVo.setUdaAppName(name);
            userDailyActivityVo.setUdaVersionCode(packageInfo.versionName);
            userDailyActivityVoList.add(userDailyActivityVo);
        }
        // 创建 Gson 实例
        Gson gson = new Gson();
        // 将 User 对象转换为 JSON 字符串
        String jsonString = gson.toJson(userDailyActivityVoList);
        //应用JSON明细
        baseVo.setUdaAllAppDetail(jsonString);

//        //系统应用
//        List<PackageInfo> packageInfoListSystem = DeviceUtils.getInstance().getAllSystemApps(this);
//        baseVo.setUdaSystemAllApp(String.valueOf(ObjectUtil.isNotEmpty(packageInfoListSystem) ? packageInfoListSystem.size() : 0));
//        List<UserDailyActivityVo> userDailyActivityVoSystemList = new ArrayList<>();
//        for (PackageInfo packageInfo : packageInfoListSystem) {
//            UserDailyActivityVo userDailyActivityVo = new UserDailyActivityVo();
//            String name = deviceUtils.getAppName(this, packageInfo.packageName);
//            userDailyActivityVo.setUdaPackage(packageInfo.packageName);
//            userDailyActivityVo.setUdaAppName(name);
//            userDailyActivityVo.setUdaVersionCode(packageInfo.versionName);
//            userDailyActivityVoSystemList.add(userDailyActivityVo);
//        }
//        // 将 User 对象转换为 JSON 字符串
//        String jsonSystemString = gson.toJson(userDailyActivityVoSystemList);
//        baseVo.setUdaSystemAllAppDetail(jsonSystemString);
        baseVo.setUmToken(UMConfigure.getUmengZID(this));

        baseVo.setToken(getSharedPreferencesToken("token"));
        hucRequestInterfase.executeStr(this, User.class, HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.INFO_URL, hucParameInterfase.getRequestParameter(baseVo), true);
    }

    private void loadVersion() {
        BaseVo baseVo = new BaseVo();
        baseVo.setToken(getSharedPreferencesToken("token"));
        hucRequestInterfase.executeStr(this, VersionUpdate.class, HUCState.HUC_REQEUST_CODE_7, Request.Method.POST, UrlConfig.URL_VERSION, hucParameInterfase.getRequestParameter(baseVo), true);
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {
        super.onSuccessfulStrType(inputType, response);
        switch (inputType) {
            case HUCState.HUC_REQEUST_CODE_1:
                loadDismiss();
                if (!(response instanceof User)) {
                    showToast(response.toString());
                    return;
                }
                User users = (User) response;

                setSharedPreferences("picture", users.getPicture());
                setSharedPreferences("id", users.getId());
                setSharedPreferences("deviceId", users.getOpenid() + users.getDeviceId());
                setSharedPreferences("loginTime", users.getLoginTime());
                setSharedPreferences("signInNumber", users.getSignInNumber());
                setSharedPreferences("signIdDayNumber", users.getSignIdDayNumber());
                if (!users.getAfbName().equals("null") || users.getAfbName().isEmpty()) {
                    setSharedPreferences("afbName", users.getAfbName());
                    setSharedPreferences("afbPhone", users.getAfbPhone());
                }
                setSharedPreferences("code", users.getCode());
                setSharedPreferences("moneyRedPacket", users.getMoneyRedPacket());
                setSharedPreferences("moneyGoldCoin", users.getMoneyGoldCoin());
                setSharedPreferences("nickname", users.getNickname());
                setSharedPreferences("usParentId", users.getUsParentId());
                String index = getSharedPreferences("currentSubject");
                setSharedPreferences("currentSubject", StrUtil.isNotEmpty(index) ? index : "0");
                String answerCount = getSharedPreferences("answerCount");
                setSharedPreferences("answerCount", StrUtil.isNotEmpty(answerCount) ? answerCount : "0");
                setSharedPreferences(RedisEnum.RISK_ADVERTISING_COINS.getKey(), users.getRisk_advertising_coins());
                setSharedPreferences(RedisEnum.RISK_ADVERTISING_COINS_THAN_EQUAL.getKey(), users.getRisk_advertising_coins_than_equal());
                setSharedPreferences(RedisEnum.RISK_ADVERTISING_COINS_THAN_EQUAL_TWO.getKey(), users.getRisk_advertising_coins_than_equal_two());
                setSharedPreferences(RedisEnum.RISK_WHITE_LIST.getKey(), users.getRisk_white_list());
//                sendIntent(this, WebGameActivity.class);
//                finish();
                break;

            case HUCState.HUC_REQEUST_CODE_7:
                if (response instanceof VersionUpdate) {
                    VersionUpdate versionUpdate = (VersionUpdate) response;
                    if (VersionUtils.getAppVersionCode(this) >= Integer.valueOf(versionUpdate.getVuVersionCode())) {
                        break;
                    }
                    //更新判断
                    if (versionUpdate.getMandatoryUpdate().equals("0")) {
//                        sendIntent(this, WebGameActivity.class);
//                        finish();
                        break;
                    } else {

                        loadVersion(versionUpdate.getVuVersionName(), versionUpdate.getVuContent(), versionUpdate.getVuUrl(), versionUpdate.getMandatoryUpdate());
                    }

                }
                break;
        }
    }

    //检测更新 start
    private void loadVersion(String usersionC, String content, String url, String mandatoryUpdate) {
        //
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        View root = LayoutInflater.from(this).inflate(R.layout.item_version, null);
        ProgressBar progressBar = root.findViewById(R.id.pb_o);
        TextView versionRoot = root.findViewById(R.id.tv_version);
        TextView tvContent = root.findViewById(R.id.tv_content);
        LinearLayout ll_mandatory = root.findViewById(R.id.ll_mandatory);
        tvContent.setText(content);
        versionRoot.setText("V" + usersionC);

        int roundRadius = 15; // 8dp 圆角半径 The x-radius of the oval used to round the corners

        //准备progressBar带圆角的背景Drawable
        GradientDrawable progressBg = new GradientDrawable();
        //设置圆角弧度
        progressBg.setCornerRadius(roundRadius);
        //设置绘制颜色
        progressBg.setColor(getResources().getColor(R.color.white_hui));

        //准备progressBar带圆角的进度条Drawable
        GradientDrawable progressContent = new GradientDrawable();
        progressContent.setCornerRadius(roundRadius);
        //设置绘制颜色，此处可以自己获取不同的颜色
        progressContent.setColor(getResources().getColor(R.color.home));

        //ClipDrawable是对一个Drawable进行剪切操作，可以控制这个drawable的剪切区域，以及相相对于容器的对齐方式
        ClipDrawable progressClip = new ClipDrawable(progressContent, Gravity.LEFT, ClipDrawable.HORIZONTAL);
        //Setup LayerDrawable and assign to progressBar
        //待设置的Drawable数组
        Drawable[] progressDrawables = {progressBg, progressClip};
        LayerDrawable progressLayerDrawable = new LayerDrawable(progressDrawables);
        //根据ID设置progressBar对应内容的Drawable
        progressLayerDrawable.setId(0, android.R.id.background);
        progressLayerDrawable.setId(1, android.R.id.progress);
        //设置progressBarDrawable
        progressBar.setProgressDrawable(progressLayerDrawable);
//        root.findViewById(R.id.tv_cancel).setVisibility(View.GONE);
        dialog.setView(root);
        root.findViewById(R.id.tv_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                root.findViewById(R.id.tv_ok).setEnabled(false);
                updateManager.showDownloadDialog(progressBar, alertDialog, url);
            }
        });
        root.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                alertDialog = null;
            }
        });
        alertDialog = dialog.create();
        alertDialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
        alertDialog.setCancelable(false);
        alertDialog.show();

        if (mandatoryUpdate.equals("2")) {
            ll_mandatory.setVisibility(View.GONE);
            root.findViewById(R.id.tv_ok).setEnabled(false);
            updateManager.showDownloadDialog(progressBar, alertDialog, url);
        } else {
            ll_mandatory.setVisibility(View.VISIBLE);
        }

    }
    //检测更新 end

    private void initAd() {
        ViewGroup viewGroup = findViewById(R.id.fl_content);
        String key = getSharedPreferences(RedisEnum.TA_KU.getKey());
        if (RedisEnum.TA_KU.getValue().equals(key)) {
            TaKuBannerAdFour taKuBannerAdFour = TaKuBannerAdFour.getInstance();
            taKuBannerAdFour.setToken(getSharedPreferencesToken("token"));
            String[] bannerKeys = getSharedPreferences(RedisEnum.BANNER.getKey()).split(",");
            if (bannerKeys.length > 5) {
                taKuBannerAdFour.load(this, bannerKeys[5], viewGroup);
            } else {
                taKuBannerAdFour.load(this, getSharedPreferences(RedisEnum.BANNER.getKey()), viewGroup);
            }
//            String banner_with = getSharedPreferences(RedisEnum.BANNER_WITH.getKey());
//            if (!TextUtils.isEmpty(banner_with)) {
//                TaKuBannerAdOBJ taKuBannerAd1 = new TaKuBannerAdOBJ();
//                taKuBannerAd1.setToken(getSharedPreferencesToken("token"));
//                taKuBannerAd1.load(this, banner_with, viewGroup);
//            }

        } else {
            MediationBannerAd mediationBannerAd = MediationBannerAd.getInstance();
            mediationBannerAd.setViewGroup(viewGroup);
            mediationBannerAd.showCacheBannerView();
        }
    }
}
